﻿
using System;
using System.Collections.Generic;

public static class ObjectExtend
{
    #region 【属性】

    //--------------------------------- 添加字典 --------------------------------------
    /// <summary>
    /// 添加字典
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <typeparam name="V"></typeparam>
    /// <param name="dict1"></param>
    /// <param name="dict2"></param>
    public static void AddRange<T, U>(this Dictionary<T, U> dict1, Dictionary<T, U> dict2)
    {
        foreach (var kvp in dict2)
        {
            if (!dict1.ContainsKey(kvp.Key))
            {
                dict1.Add(kvp.Key, kvp.Value);
            }
        }
    }

    //--------------------------------- 移除字典数据 --------------------------------------
    /// <summary>
    /// 移除字典数据
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <typeparam name="U"></typeparam>
    /// <param name="dict"></param>
    /// <param name="t"></param>
    public static void RemoveData<T, U>(this Dictionary<T, U> dict, T t)
    {
        if (dict.ContainsKey(t))
        {
            dict.Remove(t);
        }
        else
        {
           // Loger.Error(t + " Is Tot Exist In dict...");
        }
    }

    /// <summary>
    /// Action回调
    /// </summary>
    /// <param name="action"></param>
    public static void ActionReturn(this Action action)
    {
        if (action != null) action();
    }

    /// <summary>
    /// Action回调
    /// </summary>
    /// <param name="action"></param>
    /// <param name="t"></param>
    public static void ActionReturn<T>(this Action<T> action, T t)
    {
        if (t != null && action != null) action(t);
    }

    #endregion

}
